﻿if (typeof Sotipha == "undefined") Sotipha = {};
if (typeof Sotipha.View == "undefined") Sotipha.View = {};
Sotipha.View.Navigation = {
    ActiveTopMenu: function () {
        $('.menus ul li').removeClass('active');
        var pathname = window.location.pathname;
        var Mod = pathname.split("/");
        var actTag = Mod[2];
        switch (actTag) {
            case 'Home':
                actTag = "#liHome";
                break;
            case 'About':
                actTag = "#liAbout";
                break;
            case 'Towntalk':
                actTag = "#liTowntalk";
                break;
            case 'Lacquerware':
                actTag = "#liLacquerware";
                break;
            case 'Gifts':
                actTag = "#liGifts";
                break;
            case 'Sale':
                actTag = "#liSale";
                break;
            case 'Partner':
                actTag = "#liPartner";
                break;
            case 'Contact':
            case  'Cart':
                actTag = "#liContact";
                break;
        }
        $(actTag).addClass('active');
    }

}

function replaceQueryString(url, param, value) {
    var preURL = "";
    var postURL = "";
    var newURL = "";
 
        var start = url.indexOf("?" + param + "=");
    if (start == -1)
        start = url.indexOf("&" + param + "=");
    if (start > -1) {
       
        var end = url.indexOf("=", start);
        preURL = url.substring(0, end) + "=" + value;

        var startRest = url.indexOf("&", end);
        postURL = "";
        if (startRest > -1) {
            postURL = url.substring(startRest);
        }
    }
    else {
        var delimeter = "";
        preURL = url;
        if (url.indexOf("?") > 0)
            delimeter = '&';
        else
            delimeter = '?';

        postURL = delimeter + param + "=" + value;
    }
    newURL = preURL + postURL;
    return newURL;
};

function ChangeLanguage(lang) {
    var url = replaceQueryString(location.href, 'lang', lang);
    window.location.assign(url);
}
$(function () {
    Sotipha.View.Navigation.ActiveTopMenu();
});